package Consumer;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class AvgConsumer {
    private static final String BROKER_URL ="tcp://localhost:61616";
    public static void main(String[] args) {
        ConnectionFactory factory = null;
        Connection connection = null;
        Session session = null;
        Queue destination = null;
        Topic topic=null;
        MessageConsumer messageConsumer = null;

        System.out.println("均值消费者");

        try {
            factory = new ActiveMQConnectionFactory(BROKER_URL);
            connection = factory.createConnection();
            connection.start();

            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
//            destination = session.createQueue("TEST");
            topic = session.createTopic("TopicTest");
//            messageConsumer = session.createConsumer(destination);
            messageConsumer = session.createConsumer(topic);


            messageConsumer.setMessageListener(new MyListener_avg());
            System.in.read();   // Pause
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                connection.close();
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }
}

